<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ko">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>게시판 등록</title>
	<script src="../js/jquery.js" type="text/javascript"></script>
	<script src="../js/validator.js" type="text/javascript"></script>
	<link rel="stylesheet" type="text/css" href="../lib/editor/stylesheets/xq_ui.css" />
	<script type="text/javascript" src="../lib/editor/javascripts/XQuared.js?load_others=1"></script>
	<script type="text/javascript" src="../lib/editor/javascripts/plugin/FileUploadPlugin.js"></script>
	<script type="text/javascript">
        function reg(frm)
        {
			if(!checkAuth()) return false;
        	if (!isTextValidate(frm.article_title, "string", 0, "제목"))			return false;
    		if (!isTextValidate(frm.article_content, "string", 0, "내용"))			return false;
    		/* if (document.getElementById('file').value != '')
	    	{
	    		if (!isTextValidate(frm.file, "image", 0, "파일"))						return false;
	    	} */
    		
    		return true;
        }
      
      	//파일 삭제
        function deleteFileBtn(bbs_id, article_id, file_id)
		{
			if(!checkAuth()) return false;
			if (confirm("정말로 삭제하시겠습니까?"))
	      	{
				location.href="../bbs/" + bbs_id + "_file_delete.do?type=edit&article_id=" + article_id+ "&file_id=" + file_id;
				return true;
			}    		
		}
      	
        $(function() {
			//첨부파일 추가		
			$('input[name=fileAdd]').click(function(){
				
				var count = 0;		
				var fileNum = 1;
				$('input:file[id="file"]').each(function(){
					count = count + 1;
					fileNum = fileNum + 1;
				});
				
				var bbs_file_count = $('[name=bbs_file_count]').val();
				var html = "<input type='file' id='file' name='file"+fileNum+"' /><br />";
			
				if(bbs_file_count <= count ){
					alert("첨부파일은 "+bbs_file_count+"개 이상 첨부할 수 없습니다.");
					return false;
				}
				
				$('#fileTD').append(html);
				
			});
        });
       
    </script>
</head>

<body>
		<!-- 본문 영역 -->
		<div id="contents">
			<!-- 제목 및 Location 영역 -->
			<div id="location">
				<h3 id="contentTitle"></h3>
				<div id="locationPath"></div>
			</div>
			<script type="text/javascript">
			// 현재 메뉴 경로를 설정한다.
			var pagePath = licationPth.split("_");
			var pathStr = "홈";
			for( var i=0; i < pagePath.length; i++ )
			{
				if (i+1 >= pagePath.length)
					pathStr += " &gt; <strong>" + pagePath[i] + "</strong>";
				else
					pathStr += " &gt; " + pagePath[i]
			}
			document.getElementById("contentTitle").innerHTML = pagePath[ pagePath.length - 1 ];
			document.getElementById("locationPath").innerHTML = pathStr;
			</script>
			<!-- 본문 내용 -->
			<div id="content">
				<form name="writeFrm" method="post" action="../bbs/${ bbsMap.BBS_ID }_proc.do" onsubmit="return reg(this);" enctype="multipart/form-data">
				<input type="hidden" name="mode" value="edit" />
				<input type="hidden" name="bbs_id" id="bbs_id" value="${ bbsMap.BBS_ID }" />
				<input type="hidden" name="bbs_file_count" id="bbs_file_count" value="${ bbsMap.BBS_FILE_COUNT}"/>
				<input type="hidden" name="file_count" id="file_count" value="${ viewMap.FILE_COUNT}"/>
				<input type="hidden" name="file_relate_id" id="file_relate_id" value="${ viewMap.FILE_RELATE_ID}"/>
				<input type="hidden" name="article_id" id="article_id" value="${ viewMap.ARTICLE_ID }" />
				<input type="hidden" name="article_editor" id="article_editor" value="${ adminInfo.admin_name }" />
				<input type="hidden" name="article_editor_id" id="article_editor_id" value="${ adminInfo.admin_id }" />
				<input type="hidden" name="article_notice_yn" id="article_notice_yn" value="N"/>
				<input type="hidden" name="article_reg_sort" id="article_reg_sort" value="${ viewMap.ARTICLE_REG_SORT}" />
    			<div class="ar">
					<span class="button btnProc01"><input type="submit" value="수정" /></span>
					<span class="button btnProc01"><a href="#" onclick="history.go(-1); return false;">취소</a></span>
				</div>
				<input type="hidden" name="mode" value="write" />
				<table cellspacing="0" cellpadding="0" border="0" class="tbl_type04">
					<colgroup>
						<col width="150px" />
						<col width="300px" />
						<col width="150px" />
						<col />
					</colgroup>
					<tbody>
						<tr>
							<th>제목</th>
							<td colspan="3"><input type="text" name="article_title" size="105" maxlength="200" value="${  viewMap.ARTICLE_TITLE }"/></td>
						</tr>
						<tr>
							<th>등록자</th>
							<td colspan="3"><input type="text" name="article_writer" size="30" maxlength="50" value="${ viewMap.ARTICLE_WRITER }" /></td>
						</tr>
						<tr>
							<th>동영상 주소</th>
							<td colspan="3"><input type="text" name="article_etc10" size="50" maxlength="100" value="${  viewMap.ARTICLE_ETC10 }"/></td>
						</tr>
						<tr>
							<th>동영상 설명</th>
							<td><textarea rows="8" cols="94" name="article_content">${  viewMap.ARTICLE_CONTENT }</textarea></td>
						</tr>
						<c:if test="${ bbsMap.BBS_FILE_YN eq 'Y' }" >
						<c:if test="${ bbsMap.BBS_FILE_COUNT ne '0'}">
						<tr>
							<th>섬네일</th>
							<td colspan="3">
								<div id="fileTD">
								<c:if test="${ viewMap.FILE_COUNT < bbsMap.BBS_FILE_COUNT }">
								<input type="file" id="file" name="file1" />&nbsp;<span class="button btnProc01"><input type="button" name="fileAdd" value="추가" /></span><br />
								</c:if>								
								</div>
								<c:forEach items="${fileListMap}" var="fileListMap">
									<span class="button btnProc01">
										<input type="button" onclick="deleteFileBtn('${bbsMap.BBS_ID}', '${viewMap.ARTICLE_ID}', '${fileListMap.FILE_ID}')" value="삭제" />
									</span>
									&nbsp;&nbsp;
									<a href="/common/download.do?fileid=${fileListMap.FILE_ID}&jobid=${fileListMap.FILE_JOB_ID}">
										<c:out value="${fileListMap.FILE_NAME}" /><br />
									</a>
								</c:forEach>
							</td>
						</tr>
						</c:if>
						</c:if>
					</tbody>
				</table>
				</form>
			</div>
		</div>
</body>
</html>
